package com.jx.mlxg.service.impl;

<<<<<<< HEAD
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
=======
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
>>>>>>> eb72a42842a7e02f996c4f2d21dc4051aa14ecf1
import com.jx.mlxg.entity.MaterialRequest;
import com.jx.mlxg.mapper.MaterialRequestMapper;
import com.jx.mlxg.service.MaterialRequestService;
import com.jx.mlxg.utils.PageResponse;
import com.jx.mlxg.utils.PageSearchRequest;
<<<<<<< HEAD
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class MaterialRequestServiceImpl extends ServiceImpl<MaterialRequestMapper, MaterialRequest> implements MaterialRequestService {
    @Autowired
=======
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MaterialRequestServiceImpl implements MaterialRequestService {
    @Resource
>>>>>>> eb72a42842a7e02f996c4f2d21dc4051aa14ecf1
    private MaterialRequestMapper materialRequestMapper;

    public PageResponse<MaterialRequest> getMaterialRequestMapper(PageSearchRequest request) {
        // 创建分页对象
        IPage<MaterialRequest> page = new Page<>(request.getPageNo(), request.getPageSize());

        // 执行分页查询
        IPage<MaterialRequest> resultPage = materialRequestMapper.selectPage(page, null);

        // 转换为通用返回对象
        PageResponse<MaterialRequest> response = new PageResponse<>();
<<<<<<< HEAD
        response.setOrderList(resultPage.getRecords());
        response.setTotal(resultPage.getTotal());
        response.setPageNo(resultPage.getCurrent());
        response.setPageSize(resultPage.getSize());
        return response;
    }

    @Override
    public Integer saveMaterialRequest(MaterialRequest materialRequest) {
        log.debug("进入saveMaterialRequestimpl方法中" + materialRequest);
        System.out.println("进入saveMaterialRequestimpl方法中" + materialRequest);
        System.out.println(materialRequest.getProductId());
        System.out.println(materialRequest.getQuantity());

        // 校验必填字段
        if (materialRequest.getProductId() == null || materialRequest.getQuantity() == null) {
            throw new IllegalArgumentException("物料名称和数量为必填字段");
        }

        // 插入数据
        materialRequestMapper.insert(materialRequest);

        // 获取生成的 requestId
        Integer generatedRequestId = materialRequest.getRequestId();
        System.out.println("Generated Request ID: " + generatedRequestId);

        // 返回生成的 requestId
        return generatedRequestId;
    }


    @Override
    public MaterialRequest getById(String id) {
        return (MaterialRequest) materialRequestMapper.selectById(id);
    }

    @Override
    public MaterialRequest selectByRequestId(Integer requestId) {
        MaterialRequest materialRequest = materialRequestMapper.selectOneByRequestId(requestId);
        System.out.println("materialRequest---->"+materialRequest);
        return materialRequest;
    }


=======
        response.setList(resultPage.getRecords());
        response.setTotal(resultPage.getTotal());
        response.setPageNo(resultPage.getCurrent());
        response.setPageSize(resultPage.getSize());
       /* QueryWrapper<MaterialRequest> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("*");
        return materialRequestMapper.selectList(queryWrapper);*/
        return response;
    }

>>>>>>> eb72a42842a7e02f996c4f2d21dc4051aa14ecf1
}
